-- utf-8
vim.g.encoding = "UFT-8"
vim.o.fileencoding = "UTF-8"

-- 光标上下保留5行
vim.o.scrolloff = 5
vim.o.sidescrolloff = 5

-- 显示行号(相对)
vim.wo.number = true
vim.wo.relativenumber = true

-- 高亮当前行
vim.wo.cursorline = true
vim.wo.cursorcolumn = true

-- 显示左侧图标
vim.wo.signcolumn = "yes"

-- 显示行长参考线(80个字符)
vim.wo.colorcolumn = "120"

-- 缩进
vim.o.tabstop = 2
vim.bo.tabstop = 2
vim.o.softtabstop = 2
vim.o.shiftround = true

vim.o.shiftwidth = 2
vim.bo.shiftwidth = 2

vim.api.nvim_command('autocmd FileType c,cpp set sw=2')
vim.api.nvim_command('autocmd FileType c,cpp set ts=2')
vim.api.nvim_command('autocmd FileType c,cpp set sts=2')


vim.api.nvim_command('autocmd FileType cs set sw=4')
vim.api.nvim_command('autocmd FileType cs set ts=4')
vim.api.nvim_command('autocmd FileType cs set sts=4')


-- 空格代替tab
vim.o.expandtab = true
vim.bo.expandtab = true
vim.o.autoindent = true
vim.bo.autoindent = true

-- 搜索
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.hlsearch = false
vim.o.incsearch = true

-- 不显示模式提醒
vim.o.showmode = false

vim.o.cmdheight = 1

-- 自动从新加载
vim.o.autoread = true
vim.bo.autoread = true

-- 禁止折行
vim.o.wrap = false
vim.wo.wrap = false

vim.o.mouse = "nv"

-- 禁止创建备份文件
vim.o.backup = false
vim.o.writebackup = false
vim.o.swapfile = false

vim.o.updatetime = 300

-- 等待输入时间
vim.o.timeoutlen = 300

-- 自动补全默认不选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"

-- 样式
vim.o.background = "dark"
vim.o.termguicolors = true
vim.opt.termguicolors = true

-- 可视化不可显示字符
vim.o.list = true
vim.o.listchars = "tab:| ,trail:·"

-- 补全增强
vim.o.wildmenu = false
vim.o.wildmode = "" -- 'longest:full,full'

vim.o.shortmess = vim.o.shortmess .. 'c'
vim.o.pumheight = 10;

vim.o.showtabline = 2
vim.opt.showcmd = true

vim.o.foldcolumn = '1'
vim.o.foldlevel = 99
vim.o.foldlevelstart = 99
vim.o.foldenable = true

vim.api.nvim_create_autocmd("InsertLeave", {
  pattern = '*',
  command = "set nopaste"
})

if vim.fn.has("win32") == 1 then
  vim.opt.clipboard:prepend { 'unnamed', 'unnamedplus' }
  local powershell_options = {
    shell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell",
    shellcmdflag =
    "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;",
    shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait",
    shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode",
    shellquote = "",
    shellxquote = "",
  }

  for option, value in pairs(powershell_options) do
    vim.opt[option] = value
  end
end

if vim.fn.has("macunix") == 1 then
  vim.opt.clipboard:append { 'unnamedplus' }
end
